package com.jiakai.cashinterfacemucon.service.impl;

import com.jiakai.cashinterfacemucon.dao.ProductMapper;
import com.jiakai.cashinterfacemucon.model.Product;
import com.jiakai.cashinterfacemucon.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;


    public int insertOrUpdate(Product record){
        int flag = 0;
        Product temp = selectByPrimaryKey(record.getProductId());
        if (null == temp){
            flag = insert(record);
        } else {
            flag = updateByPrimaryKey(record);
        }
        return flag;
    }

    @Override
    public List<Product> findAllProductId() {
        return productMapper.findAllProductId();
    }

    public List<Product> findAll(){
        return productMapper.findAll();
    }

    @Override
    public List<Product> findAllUnbind() {
        return productMapper.findAllUnbind();
    }

    @Override
    public int deleteByPrimaryKey(String productId) {
        return productMapper.deleteByPrimaryKey(productId);
    }

    @Override
    public int insert(Product record) {
        return productMapper.insert(record);
    }

    @Override
    public int insertSelective(Product record) {
        return 0;
    }

    @Override
    public Product selectByPrimaryKey(String productId) {
        return productMapper.selectByPrimaryKey(productId);
    }

    @Override
    public int updateByPrimaryKeySelective(Product record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(Product record) {
        return productMapper.updateByPrimaryKey(record);
    }
}
